﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ESRI.ArcGIS.ADF.BaseClasses;
using PlanningGIS.Framework;
using System.Drawing;
using ESRI.ArcGIS.Geometry;

namespace PlanningGIS.Product
{
    /// <summary>
    /// 行政区查询
    /// </summary>
    public class XZQQueryCmd : BaseCommand
    {
        /// <summary>
        /// 
        /// </summary>
        IApplication m_Application = null;

        /// <summary>
        /// 
        /// </summary>
        FrmRegionQuery thisform = null;
       
        /// <summary>
        /// 
        /// </summary>
        public XZQQueryCmd()
        {
            base.m_caption = "行政区查询";
            base.m_toolTip = base.m_caption;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="hook"></param>
        public override void OnCreate(object hook)
        {
            if (m_Application == null)
            {
                m_Application = hook as IApplication;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        public override void OnClick()
        {
            if (m_Application == null) return;
            if (thisform == null || thisform.IsDisposed)
            {
                thisform = new FrmRegionQuery();
                thisform.Application = this.m_Application;
                thisform.FormClosed += thisform_FormClosed;
                thisform.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
                thisform.Show((m_Application as IFramework).MdiForm);
            }
            else
            {
                thisform.BringToFront();
            }

        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void thisform_FormClosed(object sender, System.Windows.Forms.FormClosedEventArgs e)
        {
            FrmRegionQuery thisform = (FrmRegionQuery)sender;
            if (!thisform.IsOK) return;
            FrmProductQuery frm = FrmProductQuery.Instance();
            frm.Map = (m_Application as IFramework).MapControl.Map;
            frm.Visible = false;
            frm.Show((m_Application as IFramework).MdiForm);
            frm.QueryGeometry(new List<IGeometry> { thisform.SelectedGeometry }, ViewD4Helper.ViewConfig.DataType.TableName, ViewD4Helper.ViewConfig.Scale);
        }
        /// <summary>
        /// 
        /// </summary>
        public override bool Enabled
        {
            get
            {
                if (m_Application == null) return false;
                return (m_Application as IFramework).IsMapCtrlactive;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public override int Bitmap
        {
            get
            {
                string bitmapResourceName = "PlanningGIS.Product.Resources." + this.GetType().Name + ".ico";
                System.IO.Stream pStream = GetType().Assembly.GetManifestResourceStream(bitmapResourceName);
                if (pStream == null) return 0;
                return new Bitmap(pStream).GetHbitmap().ToInt32();
            }
        }

    }
}
